package com.zaimokuza.cn.controller;

import com.zaimokuza.cn.entity.response.ResponseFormat;
import com.zaimokuza.cn.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @author zaimokuza
 */
@Api(tags = "文件相关接口")
@ResponseFormat
@RestController
@RequestMapping("/file")
public class FileController {

    @Resource
    private FileService fileService;

    @ApiOperation(value = "上传头像", notes = "上传头像")
    @PostMapping("/upload/avatar")
    public String uploadAvatar(@RequestParam MultipartFile file) throws IOException {
        return fileService.uploadAvatar(file);
    }

    @ApiOperation(value = "上传图片", notes = "上传图片")
    @PostMapping("/upload/image")
    public String uploadImage(@RequestParam MultipartFile file) throws IOException {
        return fileService.uploadImage(file);
    }

}
